﻿using Fozzy.Ontology;
using System.Collections.Generic;

namespace Fozzy.Gedcom
{
    /// <summary>
    /// One family group. 
    /// </summary>
    [XAlias("INDI")]
    [XLevel(0)]
    public class Person2                         : Fozzy.Being.Person
    {
        #region States
            public bool                         Be_Alive            { get { return Death.Exists                                     ; } }
        #endregion

        #region Properties
            public Fozzy.Identifier             Identifier          { get { return new Identifier       (Element)                   ; } }
            public override Fozzy.Name          Name                { get { return new Name             (Element)                   ; } }
            public Photos                       Photos              { get { return new Photos           (Element)                   ; } }
            public Story                        Story               { get { return new Story            (Element)                   ; } }
            public Photo                        Avatar              { get { return Photos.First                                     ; } }
            private Header                      Header              { get { return ((Identifier)Identifier).Header(Name)            ; } }
        #endregion

        #region Birth-Death
            public Birth                        Birth               { get { return new Birth    (Element)                            ; } }
            public Death                        Death               { get { return new Death    (Element)                            ; } }
        #endregion

        #region Constructeur
            public Person2()
            {}
            public Person2(_Element node)                             : base(node)
            {}
        #endregion

            //public override void Export(Fozzy.File file)
            //{
            //    base    .Export(file)                               ;
            //    Header  .Export(file)                               ;
            //    Name    .Export(file)                               ;
            //    Gender  .Export(file)                               ;
            //    Birth   .Export(file)                               ;
            //    Death   .Export(file)                               ;
            //    Photos  .Export(file)                               ;
            //}

            public void Add(string photo)
            {
                Add(new Photo(photo))                               ;
            }

            public void Add(IEnumerable<string> photos)
            {
                foreach (string photo in photos)
                {
                    Add(new Photo(photo))                           ;
                }
            }

            ///// <summary>
            ///// Import the note info from the GEDCOM XMl file.
            ///// </summary>
            //[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
            //private static void ImportNote(Person person, XmlNode node)
            //{
            //    try
            //    {
            //        string value = GetValue(node, "NOTE");
            //        if (!string.IsNullOrEmpty(value))
            //        {
            //            person.Story = new Story();
            //            string storyFileName = new StringBuilder(person.Name).Append(".rtf").ToString();
            //            person.Story.Save(value, storyFileName);
            //        }
            //    }
            //    catch
            //    {
            //        // There was an error importing the note, ignore
            //        // and continue processing the GEDCOM XML file.
            //    }
            //}



            //public void Add(IEnumerable<Photo> photos)
            //{
            //    try
            //    {
            //        //photos.Ruben().Be_Avatar.True()                     ;  
            //        // Get list of photos for this person.
            //        //string[] photos = GetPhotos(node);
            //        //if (photos == null || photos.Length == 0)
            //        //    return;

            //        // Import each photo. Make the first photo specified
            //        // the default photo (avatar).
            //        //for (int i = 0; i < photos.Length; i++)
            //        //foreach(Photo photo in photos)
            //        //{
            //        //    //Photo photo = new Photo(photos[i]);
            //        //    //photo.IsAvatar = (i == 0) ? true : false;
            //        //    Photos.Add(photo);
            //        //}
            //    }
            //    catch
            //    {
            //        // There was an error importing a photo, ignore 
            //        // and continue processing the GEDCOM XML file.
            //    }
            //}

        //private void ImportPeople()
        //{
        //// Get list of people.
        //XmlNodeList list = doc.SelectNodes("/root/INDI");

        //foreach (XmlNode node in list)
        //{
        //    // Create a new person that will be added to the collection.
        //    Person person = new Person();

        //    // Import details about the person.
        //    person.FirstName = GetFirstName(node);
        //    person.LastName = GetLastName(node);
        //    person.NickName = GetNickName(node);
        //    person.Suffix = GetSuffix(node);
        //    person.MarriedName = GetMarriedName(node);

        //    person.Id = GetId(node);
        //    person.Gender = GetGender(node);

        //    ImportBirth(person, node);
        //    ImportDeath(person, node);

        //    //Pas besoin d'importer : C'est à l'intérieur de la Person
        //    //ImportPhotos(person, node);
        //    ImportNote(person, node);

        //    people.Add(person);
        //}
        //}


    }
}
